package cPanes;


import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;

import javax.swing.BorderFactory;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.border.BevelBorder;


/*
 * An empty CPane which exists mostly to test functionality. Could be used to color code different areas of the screen.
 */
public class OrgPane extends CPane {

	private JMenu colors;
	private JMenuItem[] pcolors;
	
	/**
	 * Performs bare-minimum setup.
	 */
	public OrgPane(){
	super();
	this.setName("ORG");
	this.setBackground(Color.lightGray);
	addColors();
	}
	
	void resizeContents(int owidth, int oheight) {
		//Nothing to resize.
	}

	public void menuActions(ActionEvent e){
		if (e.getSource().equals(pcolors[0])) setBackground(Color.BLUE);
		else if (e.getSource().equals(pcolors[1])) setBackground(Color.ORANGE);
		else if (e.getSource().equals(pcolors[2])) setBackground(Color.GREEN);
		else if (e.getSource().equals(pcolors[3])) setBackground(Color.PINK);
		else if (e.getSource().equals(pcolors[4])) setBackground(Color.WHITE);
		else if (e.getSource().equals(pcolors[5])) setBackground(Color.BLACK);
		else if (e.getSource().equals(pcolors[6])) setBackground(Color.RED);
		else if (e.getSource().equals(pcolors[7])) setBackground(Color.YELLOW);
		else if (e.getSource().equals(pcolors[8])) setBackground(Color.GRAY);
	}
	
	/**
	 * Creates a menu of possible background colors and adds them to the content menu.
	 */
	private void addColors(){
		colors = new JMenu("Color");
		pcolors=new JMenuItem[9];
		pcolors[0] = new JMenuItem("Blue");
		pcolors[1] = new JMenuItem("Orange");
		pcolors[2] = new JMenuItem("Green");
		pcolors[3] = new JMenuItem("Pink");
		pcolors[4] = new JMenuItem("White");
		pcolors[5] = new JMenuItem("Black");
		pcolors[6] = new JMenuItem("Red");
		pcolors[7] = new JMenuItem("Yellow");
		pcolors[8] = new JMenuItem("Gray");
		for (int i=0; i<pcolors.length; i++){
			pcolors[i].addActionListener(this.getMenu());
			colors.add(pcolors[i]);
		}
		this.getMenu().add(colors);
	}

	void mouseActions(MouseEvent e, String type) {
		//This panel has no special mouse actions
	}

	
	 
	public void openSave(String s) {
		//Reads the red, green and blue components of the background color as Integers separated by '/'
		String[] t = s.split("/");
		Color c = new Color(Integer.parseInt(t[0]), Integer.parseInt(t[1]), Integer.parseInt(t[2]));
		this.setBackground(c);
	}

	public String returnSave() {
		//Saves the red, green and blue components of the background color, separated by '/'
		return String.valueOf(this.getBackground().getRed()) + "/" + String.valueOf(this.getBackground().getGreen()) 
			+ "/" + String.valueOf(this.getBackground().getBlue());
	}

}
